package com.lishuang.DAO.DeviceDAO;

import com.lishuang.DAO.SqlConnector;
import com.lishuang.domain.json.Device;

import java.util.List;

/**
 * @author LiShuang
 * @version 1.0.0
 * @date 2022/11/12 18:02
 */
public class deviceDAOProxy implements deviceDAO {
    private SqlConnector sql;
    private deviceDAOImp daoImp;
    public deviceDAOProxy() throws Exception {
        sql = new SqlConnector();
        daoImp = new deviceDAOImp(sql);
    }
    @Override
    public boolean Insert(Device device) throws Exception {
        boolean flag = false;
        if(daoImp.findByIdx(device.getDeviceId())==null){
            flag = daoImp.Insert(device);
        }
        sql.close();
        return flag;
    }

    @Override
    public List<Device> findAll() throws Exception {
        List<Device>list = daoImp.findAll();
        sql.close();
        return list;
    }

    @Override
    public Device findByIdx(int deviceId) throws Exception {
        Device device = daoImp.findByIdx(deviceId);
        sql.close();
        return device;
    }
}
